import java.util.*;
import java.util.Scanner;

public class Main {
    public List<Integer> findSubstring(String ss, String[] tt) {
        List<Integer> ret=new ArrayList<>();
        Map<String,Integer> hash1=new HashMap<>();
        int n=tt.length,m=tt[0].length();
        for(String t:tt){
            hash1.put(t,hash1.getOrDefault(t,0)+1);
        }
        for(int i=0;i<m;i++){
            Map<String,Integer> hash2=new HashMap<>();
            for(int left=i,right=i,count=0;right+m<=ss.length();right+=m){
                String in=ss.substring(right,right+m);
                hash2.put(in,hash2.getOrDefault(in,0)+1);
                if(hash2.get(in)<=hash1.getOrDefault(in,0)) count++;
                if(right-left+1>m*n){
                    String out=ss.substring(left,left+m);
                    if(hash2.get(out)<=hash1.getOrDefault(out,0)) count--;
                    hash2.put(out,hash2.get(out)-1);
                    left+=m;
                }
                if(count==n) ret.add(left);
            }
        }
        return ret;
    }
    public List<Integer> findAnagrams(String ss, String pp) {
        List<Integer> ret=new ArrayList<>();
        char[] s=ss.toCharArray();
        char[] p=pp.toCharArray();
        if(s.length<p.length) return ret;
        int[] hash1=new int[26];
        int[] hash2=new int[26];
        int n=p.length;
        for(char ch:p) hash1[ch-'a']++;
        for(int left=0,right=0,count=0;right<s.length;right++){
            char in=s[right];
            if(++hash2[in-'a']<=hash1[in-'a']) count++;
            if(right-left+1>p.length){
                char out=s[left++];
                if(hash2[out-'a']--<=hash1[out-'a']) count--;
            }
            if(count==n){
                ret.add(left);
            }
        }
        return ret;
    }
}